package com.es.code.user.controller;


import com.es.code.annotation.LogAround;
import com.es.code.commons.ResultConstant;
import com.es.code.commons.ResultData;
import com.es.code.user.service.EsUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jichf
 * @Description
 * @create 2021-11-04 9:30
 */

@Api(tags = "用户信息管理")
@RestController
@RequestMapping(value = "/user")
public class EsUserController {

    @Autowired
    private EsUserService esUserService;
    /**
     * 创建user索引
     * @return
     */

    @ApiOperation(value = "创建user索引")
    @RequestMapping(value = "/createIndex", method = RequestMethod.GET)
    @LogAround(value = "创建user索引")
    public ResultData createIndex() {
        try {
            return esUserService.createEsIndex();
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultData(ResultConstant.FAILED,e.getMessage());
        }
    }

    /**
     * 删除user索引
     * @return
     */
    @ApiOperation(value = "删除user索引")
    @RequestMapping(value = "/deleteIndex", method = RequestMethod.GET)
    @LogAround(value = "删除user索引")
    public ResultData deleteIndex(){
        try {
            return esUserService.deleteEsIndex();
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultData(ResultConstant.FAILED,e.getMessage());
        }
    }

    @ApiOperation(value = "查看用户数据的索引有没有创建")
    @RequestMapping(value = "/existIndex", method = RequestMethod.GET)
    @LogAround(value = "查看用户数据的索引有没有创建")
    public ResultData existEsIndex(){
        try {
            return esUserService.existEsIndex();
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultData(ResultConstant.FAILED,"获取信息异常");
        }
    }
}
